package com.prj.ufdm.cloud.svr.gateway.bpo._impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.prj.ufdm.cloud.base.dto.RetData;
import com.prj.ufdm.cloud.base.enums.BaseRetCodeEnum;
import com.prj.ufdm.cloud.svr.gateway.bpo.LogBPO;

@Service 
public class LogBPOImpl implements LogBPO {

	@Async
	@Override
	public void enableUserLoginLog(String username, RetData<Map<String, Object>> retData,ServerHttpRequest request) throws Exception {
		
		HttpHeaders httpHead = request.getHeaders();
		Map<String,String> paramMap = new HashMap<String,String>();
		paramMap.put("serverType", "08");
		paramMap.put("logType", "1");
		paramMap.put("userName", username);
		paramMap.put("idAddress", request.getRemoteAddress()!=null ? request.getRemoteAddress().getHostString() : "-1"); 
		paramMap.put("browser",httpHead.getFirst("User-Agent"));
		if(retData.getRetHead().getCode().equals(BaseRetCodeEnum.RET_CODE_0000000.getCode())) {
			paramMap.put("status", "1");
		}
		else {
			paramMap.put("status", "2");
		}
		paramMap.put("content", retData.getRetHead().getMessage());
	}
}
